package com.spsoft.workflow.common.enums;

import cn.hutool.core.util.RandomUtil;
import com.spsoft.core.utils.DateUtils;
import com.spsoft.core.utils.StringUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Date;

/**
 * 流程类型
 *
 * @author cdl
 * @date 2023/11/22
 */
@Getter
@AllArgsConstructor
public enum BusFlowTypeEnums {


    /**
     * 手工开具发票
     */
    FLOW_SGKP("FLOW_SGKP","手工开具发票"),
    /**
     * 预赋码领用
     */
    FLOW_YFMLY("FLOW_YFMLY","预赋码领用"),
    /**
     * 下载授信额度
     */
    FLOW_XZSXED("FLOW_XZSXED","下载授信额度"),
    /**
     * 退回授信额度
     */
    FLOW_THSXED("FLOW_THSXED","退回授信额度"),
    /**
     * 数电红字确认单申请
     */
    FLOW_HZQRDSQ("FLOW_HZQRDSQ","数电红字确认单申请"),
    /**
     * 数电红字确认单确认
     */
    FLOW_HZQRDQR("FLOW_HZQRDQR","数电红字确认单确认"),
    /**
     * 发票匹配流水
     */
    FLOW_PPLS("FLOW_PPLS","发票匹配流水"),
    /**
     * 发票匹配流水撤销
     */
    FLOW_PPLSCX("FLOW_PPLSCX","发票匹配流水撤销");



    private final String code;
    private final String typeDesc;


    /**
     * 根据不同的类型生成流程编号
     */
    public static String getFlowCode(BusFlowTypeEnums busFlowTypeEnums) {
        String dataString = DateUtils.formatDate(new Date(), DateUtils.PURE_DATETIME_PATTERN);
        //随机数
        String randomString = StringUtil.toString(RandomUtil.randomInt(4));
        String flowCode = "";
        if(busFlowTypeEnums !=null){
            flowCode = busFlowTypeEnums.getCode() + dataString + randomString;
        }
        return flowCode;
    }
    public static String getTypeDesc(String code) {
        BusFlowTypeEnums[] busFlowTypeEnums = values();
        for (BusFlowTypeEnums os : busFlowTypeEnums) {
            if (os.code.equals(code)) {
                return os.getTypeDesc();
            }
        }
        return null;
    }

    /**
     * 获取流名称
     *
     * @param code     编码
     * @param userName 用户名
     * @return {@link String}
     */
    public static String getFlowName(String code,String userName) {
        BusFlowTypeEnums b = BusFlowTypeEnums.valueOf(code);
        return userName+"提交的"+b.getTypeDesc()+"申请";
    }
}
